import { createBrowserRouter } from "react-router-dom";
import App from "@/pages/App";
import ErrorPage from "../pages/error-page";
import Index from "@/pages";
import basic from "./routes/basic";
import items from "@/config/nav";
import { lazy } from "react";

// console.log(items);
const routes=items.map((item) => {
  return {
    path: item.label.path,
    children: item.children
      .map((gg) => ({
        path: gg.label.path,
        // 下面这里有个问题，import中不能有变量存在
        Component: lazy(()=>import(`@/pages/${item.label.path}/${gg.label.path}`)),//所以这里用不了！！！
      })).concat({ index: true, element: <Index /> })
  };
});
console.log(routes[0]);
console.log(basic);
console.log(import.meta);





const router = createBrowserRouter([
  {
    path: "/",
    element: <App />,
    errorElement: <ErrorPage />,
    children: [
      {
        errorElement: <ErrorPage />,
        children: [
          // 开始界面
          { index: true, element: <Index /> },
          basic,
        ],
      },
    ],
  },
]);

export { router }; // 统一暴露；
